package com.hyt.it.ogt.ks.api.ua;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.feign.KwClient;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 刘恒活
 * @since 2020/10/14 14:12
 */
@Api(tags = "8.考试对外权限系统接口", value = "考试对外权限系统接口")
@ApiSort(8)
@RestController
@RequestMapping("/api/ks/ua/")
@Slf4j
public class UaApi {

    @Resource
    private KwClient kwClient;

    @ApiOperationSort(1)
    @ApiOperation(value = "8.1.1 校验账号是否存在", notes = "状态码：18001:成功，18330：异常", response = String.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "examId", value = "考试ID", dataType = DataType.STRING,
            paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "admissionNumber", value = "准考证号", dataType = DataType.STRING,
                    paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "from", value = "1-正常登录页面，2-统一登录界面", dataType = DataType.STRING,
                    paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "loginType", value = "登录类型：1-身份证号 ，2-手机号 ，3-准考证号",
                    dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)})
    @GetMapping("validCandidateAccount")
    public ApiResponse<String> validCandidateAccount(@RequestParam String examId, @RequestParam String admissionNumber,
                                                     @RequestParam String from, @RequestParam String loginType) {
        try {
            return kwClient.validCandidateAccount(examId, admissionNumber, from, loginType);
        } catch (Exception e) {
            log.error("{}", e);
            return ApiResponse.<String>builder().code(BizStatusCode.VALID_CANDIDATE_ACCOUNT.getCode()).build();
        }
    }
}
